package com.ushine.web.base.model.system;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ushine.web.base.model.base.BaseBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Author: yls
 * @Date 2022/2/15 14:01
 * @Description: 用户组
 * @Version 1.0
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@ApiModel(description = "用户组表")
@Table(name = "t_system_user_group")
@org.hibernate.annotations.Table(appliesTo = "t_system_user_group", comment = "用户组表")
@TableName(value = "t_system_user_group")
@EntityListeners(AuditingEntityListener.class)
public class UserGroupDO extends BaseBO implements Serializable {

    /**
     * 编号
     * // 解决前台js接收雪花id精度丢失问题
     * JsonFormat(shape = JsonFormat.Shape.STRING)
     */
    @Id
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty("编号")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Column(name = "id", columnDefinition = "bigint comment '编号'")
    private Long id;

    /**
     * 用户组名称
     */
    @ApiModelProperty("用户组名称")
    @Column(name = "user_group_name", columnDefinition = "varchar(32) comment '用户组名称'")
    @Length(max = 32, message = "用户组名称最大为：32")
    @NotBlank(message = "用户组名称不能为空")
    private String userGroupName;

    /**
     * 父级用户组id
     */
    @ApiModelProperty("父级用户组id")
    @Column(name = "parent_id", columnDefinition = "bigint comment '父级用户组id'")
    @NotNull(message = "父级用户组id不能为空")
    private Long parentId;

    /**
     * 备注
     */
    @ApiModelProperty("备注")
    @Column(name = "remarks", columnDefinition = "varchar(255) comment '备注'")
    @Length(max = 255, message = "备注的最大长度为：255")
    private String remarks;

    /**
     * 逻辑删除
     * TableField => select:false (在查询的时候排除该字段)
     */
    @TableLogic
    @TableField(value = "is_deleted", fill = FieldFill.INSERT, select = false)
    @ApiModelProperty(value = "逻辑删除", example = "0")
    @Column(name = "is_deleted", columnDefinition = "datetime comment '删除标记=> 不为null：已删除，为空：未删除'")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime deleted;
}
